namespace Asmex.FileViewer
{
    using System;
    using System.Collections;
    using System.Reflection;

    public abstract class MDHeap : Region, ICollection, IEnumerable
    {
        protected SortedList _data = new SortedList();
        protected string _name;

        public void CopyTo(Array arr, int idx)
        {
            for (int i = 0; i < this._data.Count; i++)
            {
                arr.SetValue(this._data[i], (int) (i + idx));
            }
        }

        public object GetByOffset(int i)
        {
            return this._data[i];
        }

        public IEnumerator GetEnumerator()
        {
            return new Enumerator(this._data.GetValueList());
        }

        public override string ToString()
        {
            string[] strArray = new string[] { this._name, "  {", base.Start.ToString("X8"), " - ", (base.Length + base.Start).ToString("X8"), "}" };
            return string.Concat(strArray);
        }

        public int Count
        {
            get
            {
                return this._data.Count;
            }
        }

        public bool IsSynchronized
        {
            get
            {
                return false;
            }
        }

        public object this[int idx]
        {
            get
            {
                return this._data.GetByIndex(idx);
            }
        }

        public object SyncRoot
        {
            get
            {
                return null;
            }
        }

        public class Enumerator : IEnumerator
        {
            private int _curr;
            private IList _data;

            public Enumerator(IList data)
            {
                this._data = data;
                this.Reset();
            }

            public bool MoveNext()
            {
                this._curr++;
                return (this._curr < this._data.Count);
            }

            public void Reset()
            {
                this._curr = -1;
            }

            public object Current
            {
                get
                {
                    return this._data[this._curr];
                }
            }
        }
    }
}
